{__NOLAYOUT__}
<div toplayer="1" class="wrap-box" id="<?php echo $funcid;?>" summaryid="GoodsBom" baseurl="<?php echo U('/Home/GoodsBom/index?func=search&id='.$goods_id); ?>">
	<input type="hidden" id="{$funcid}-last-url" value="{$__last_url}" />
	<input type="hidden" id="<?php echo $funcid;?>-selected-company-id" value="" />
	<input type="hidden" id="<?php echo $funcid;?>-selected-bom-id" value="" />
	<input type="hidden" id="<?php echo $funcid;?>-root-bom-id" value="<?php echo $goods_bom['id'] ?>" />
<!--
	<div class="wrap-title abe-ofl">
        <div class="tit abe-fl">物品分类</div>
        <div class="abe-fr">

          <?php if (isset($rights['add']) && $rights['add']): ?>
               
          <?php endif; ?>
          <em class="abe-space-sm"></em>
          <a href="javascript:void(0);" class="vi-blue " onclick="return _asr.openLink('<?php echo U('/Home/EffectsCategory/index?func=search'); ?>','<?php echo "$funcid"; ?>','刷新',1); "><i class="iconfont">&#xe611;</i> 刷新</a>
        </div>
   </div>
-->
   <php>

   </php>
   <div class="new-trees-box" style="position:relative;">
        <div class="trees-nav trees-nav-new tree-wl-bg tree-nstyle">
            <input type="checkbox" style="display: none;" name="code" value="">
            <div class="trees-nav-new-in" id="<?php echo $funcid;?>-trees-nav-new-in">
                <div class="tree-title vi-blue">公司物品分类</div>
                <?php if(!empty($categoty_list)) { ?>
                        <php>echo showcategory($categoty_list,$funcid);</php>
                    <?php } ?>
            </div>
        </div>

        <div class="new-trees-info" id="<?php echo $funcid;?>-new-trees-info" style="padding-left:280px;">
            <include file="EffectsCategory/info" />
        </div>
    </div>
</div>
<script>
	function <?php echo $funcid ?>_refresh_node(parent_id, goods_id) {
		var _list = $("#<?php echo $funcid;?>").find("div[data-parent=parent-<?php echo $funcid;?>-" + parent_id + "]");
		_list.html("");
		var _root = $("#<?php echo $funcid;?>-root-bom-id").val();
		var _funcid = '<?php echo $funcid;?>';
		var _url = '<?php echo U("/Home/GoodsBom/index") ?>' + "?func=loadbom&goods_id=" + goods_id + "&parent_id=" + parent_id + "&r=1&rootbom=" + _root;
		_list.parent().find("i").eq(0).attr("class", "iconfont arrow-deg");
		_asr.loadData(_funcid, _url);
	}



	function <?php echo $funcid ?>_load_bom(obj){
        var cur_div=$(obj).parent().parent().children("ul");
	    $(cur_div).toggle();
        if($(cur_div).is(":hidden"))
        {
            if($(obj).parent().parent().children('a[data-type="0"]').length>0)
            {
                $(obj).parent().parent().find("i:eq(0)").find("a").html("&#xe708;");
            }
            else
            {
                $(obj).parent().parent().find("i:eq(0)").removeClass("arrow-deg");
            }
        }else
        {
            if($(obj).parent().parent().children('a[data-type="0"]').length>0)
            {
                $(obj).parent().parent().find("i:eq(0)").find("a").html("&#xe707;");
            }
            else
            {
                $(obj).parent().parent().find("i:eq(0)").addClass("arrow-deg");
            }

        }

	}
	
	function <?php echo $funcid ?>_load_bom_info(id,t) {
		if(t==1)
        {
            $("#<?php echo $funcid;?>-selected-bom-id").val(id);
        }else
        {
            $("#<?php echo $funcid;?>-selected-company-id").val(id);
            $("#<?php echo $funcid;?>-selected-bom-id").val("");
        }

		var _funcid ='{$funcid}';
        //"<?php echo $funcid;?>-new-trees-info"; //_asr.createFuncId();
		//var _root = $("#<?php echo $funcid;?>-root-bom-id").val();
		var _url = '<?php echo U("/Home/EffectsCategory/index") ?>' + "?func=loadcategoryinfo&t="+t+"&id=" + id + "&pfuncid=<?php echo $funcid;?>";
		$("#<?php echo $funcid;?>-trees-nav-new-in").find("a").each(function() {
			_asr.removeClass($(this), "active");
		});
        $("a[tree-date-type=title][data-type="+t+"][data-id="+id+"]").addClass("active");
        if($("a[tree-date-type=title][data-type="+t+"][data-id="+id+"]").parent().children("ul").is(":hidden"))
        {
            $("a[tree-date-type=title][data-type="+t+"][data-id="+id+"]").parent().children("ul").show();
        }
		return _asr.loadData(_funcid, _url, null, <?php echo $funcid ?>_append_info);
	}

    function {$funcid}_select_company(obj)
    {
        $("#<?php echo $funcid;?>-selected-company-id").val($(obj).attr("data-id"));
        $("#<?php echo $funcid;?>-selected-bom-id").val("");
        $("#<?php echo $funcid;?>-trees-nav-new-in").find("a").each(function() {
            _asr.removeClass($(this), "active");
        });
        $("#{$funcid}-new-trees-info .new-trees-scroll .new-trees-scroll-in").children("div:gt(0)").hide();
        $(obj).addClass("active");
    }

	function <?php echo $funcid ?>_load_bom_callback(parent_id, list, r) {
		var _list = $("div[data-parent=parent-<?php echo $funcid;?>-" + parent_id + "]");
		var _html = "<ul>";

		for(var k in list){
			var _url = '<?php echo U("/Home/GoodsBom/index") ?>' + "?func=loadbominfo&id=" + list[k]["id"];
			var _funcid = _asr.createFuncId();
			_html += "<li>";
			_html += "<i class=\"iconfont" + (list[k]['children'] == 0 ? " no-child" : "") + "\"><a href=\"javascript:void(0);\" onclick=\"<?php echo $funcid; ?>_load_bom(" + list[k]["id"] + ", " + list[k]["goods_id"] + ");\"></a></i>";
			_html += "<a href=\"javascript:void(0);\"" + (list[k]['is_include'] == 0 ? "class=\"tree-ch-link\"" : "" ) + " tree-date-type=\"title\" onclick=\"return <?php echo $funcid ?>_load_bom_info(" + list[k]["id"] + ", " + list[k]["goods_id"] + ");\" >" + list[k]["code"] + "-" + list[k]["name"] + (list[k]["link_code"] ? "(" + list[k]["link_code"] + ")" : "") + "</a>";
			_html += "<div data-parent=\"parent-<?php echo $funcid;?>-" + list[k]["id"] + "\"></div>";
			_html += "</li>";
		}

		_html += "</ui>";
		_list.append(_html);
		if(typeof(r) != 'undefined' && r > 0) {
			<?php echo $funcid ?>_load_bom_info(parent_id, r);
		}
	}
	
	function <?php echo $funcid ?>_append_info(c) {
		var _obj = $("#<?php echo $funcid;?>-new-trees-info");
		_obj.empty();
		_obj.html(c);
        $("#{$funcid} .new-trees-scroll-in .pub-par-title span").html($("a[tree-date-type=title].active").attr("data-path"));

    }
	
	function {$funcid}_category_add(){
		var _companyid = $("#<?php echo $funcid;?>-selected-company-id").val();
        var pid = $("#<?php echo $funcid;?>-selected-bom-id").val();
        if(pid==undefined || pid=="")
        {
            if(_companyid==undefined || _companyid=="")
            {
                _asr.message("警告","必须选择一个公司或分类","");
                return;
            }
        }

		var url = '<?php echo U("/Home/EffectsCategory/index"); ?>';
        url += "?func=add&ofuncid=<?php echo $funcid;?>";
		if(pid!=undefined && pid>0)
        {
            url +="&pid="+pid;
        }else
        {
            url +="&company_id="+_companyid;
        }
		return _asr.popupFun(url);
	}

    function {$funcid}_category_add_callback(content){
        var curdata=eval(content);
        var pel=undefined;
        if(curdata.parent_id==undefined || curdata.parent_id==0)
        {
            //pel=$("ul[data-parent='parent-{$funcid}-0'] a[data-id="+ curdata.company_id +"]");
            //pel=$("ul[data-parent='parent-{$funcid}-0'] a[data-type='0'][data-id="+ curdata.company_id +"]");
            pel=$("a[data-type='0'][data-id="+ curdata.company_id +"]");
        }else
        {
            pel=$("a[data-type='1'][data-id="+ curdata.parent_id +"]");
            //pel=$("ul[data-parent='parent-{$funcid}-"+ curdata.parent_id +"']");
        }
        if(pel.length>0)
        {
            if($(pel).parent().children("ul").length<=0)
            {
                $(pel).parent().append('<ul  data-parent="parent-{$funcid}-'+curdata.parent_id+'" style="display:none"></ul>');
            }
            $(pel).parent().children("ul").show();
            var el=$(pel).parent().children("ul").find("a[data-type='1'][data-id='"+ curdata.id +"']");
            if(el.length<=0)
            {

                //var cur_li='<li><i class="iconfont no-child"><a href="javascript:void(0);" onclick="{$funcid}_load_bom(this);" class="">&#xe618;</a></i><a data-type="1" data-id="'+curdata.id+'"  href="javascript:void(0);" tree-date-type="title" onclick="{$funcid}_load_bom_info('+ curdata.id +');" class="">'+ curdata.name +'</a></li>';
                var cur_li='<li><i class="iconfont no-child"><a href="javascript:void(0);" onclick="{$funcid}_load_bom(this);">&#xe618;</a></i><a data-type="1" data-id="'+curdata.id+'"  href="javascript:void(0);" tree-date-type="title" onclick="{$funcid}_load_bom_info('+ curdata.id +',1);" class="">'+ curdata.name +'</a></li>';
                $(pel).parent().children("ul").append(cur_li);
            }else
            {
                $(el).html(curdata.name);
                {$funcid}_load_bom_info(curdata.id,1);
            }
        }
    }


    function {$funcid}_category_delete_callback(content){
        var curdata=eval(content);
        var pel=undefined;

        $("a[data-type='1'][data-id="+ curdata.id +"]").parent().remove();
        if(curdata.parent_id==undefined || curdata.parent_id==0)
        {
            pel=$("a[data-type='0'][data-id="+ curdata.company_id +"]");
        }else
        {
            pel=$("a[data-type='1'][data-id="+ curdata.parent_id +"]");
        }
        $(pel).click();
    }


    function {$funcid}_effects_add(){
        var pid = $("#<?php echo $funcid;?>-selected-bom-id").val();
        if(pid==undefined || pid=="")
        {
                _asr.message("警告","必须选择一个分类","");
                return;
        }

        var url = '<?php echo U("/Home/EffectsCategory/index"); ?>';
        url += "?func=detail_add&ofuncid=<?php echo $funcid;?>";
        url +="&category_id="+pid;

        return _asr.popupFun(url);
    }

</script>